(function ($) {

    $.fn.skartAjax = function (options) {

        // Establish our default settings
        var mySettings = $.extend({
            url: null,
            method: "GET",
            data: {},
            async: true,
            processData: false,
            contentType: "application/json; charset=utf-8",
            beforeSend: null,
            error: null,
            success: null,
            complete: null,
            loaderButtonSelector: ""
        }, options);

        // var myThis = $(this);
        //myThis.html("<div class='blockUI blockMsg blockElement' style='text-align:center; margin:10px auto;'><div class='loading-message loading-message-boxed'><img src='../../../../../Content/Template/assets/global/img/loading-spinner-grey.gif' align=''><span>&nbsp;&nbsp;LOADING...</span></div></div>");

        $.ajax({
            url: mySettings.url,
            method: mySettings.method,
            data: mySettings.data,
            async: mySettings.async,
            //processData: mySettings.processData,
            contentType: mySettings.contentType,
            beforeSend: function (jqXhr, settings) {
                if (mySettings.beforeSend != null) {
                    mySettings.beforeSend(jqXhr, settings);
                }

                //Ladda-LoaderButton
                StartButtonLoading(mySettings.loaderButtonSelector);
            },
            error: function (jqXhr, textStatus, errorThrown) {
                if (mySettings.error != null) {
                    mySettings.error(jqXhr, textStatus, errorThrown);
                }
            },
            success: function (data, textStatus, jqXhr) {
                CheckAuth(data);

                if (mySettings.success != null) {
                    mySettings.success(data, textStatus, jqXhr);
                }

                $.validator.unobtrusive.parse("form");
            },
            complete: function (jqXhr, textStatus) {
                if (mySettings.complete != null) {
                    mySettings.complete(jqXhr, textStatus);
                }

                //Ladda-LoaderButton
                StopButtonLoading(mySettings.loaderButtonSelector);
            }
        });
    }

}(window.jQuery));
